/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/


#include "d3d_local.h"


/*-----------------------------------------------------------------------------
	RS and D3D format conversion :
-----------------------------------------------------------------------------*/

const D3DFORMAT	format_x_table[RS_FORMAT_MAX] = {
	D3DFMT_UNKNOWN,				//	RS_FORMAT_UNKNOWN				
	D3DFMT_X8R8G8B8,			//	RS_FORMAT_XRGB_U8				
	D3DFMT_A8R8G8B8,			//	RS_FORMAT_ARGB_U8				
	D3DFMT_A2R10G10B10,			//	RS_FORMAT_ARGB_U10				
	D3DFMT_A16B16G16R16F,		//	RS_FORMAT_ARGB_F16				
	D3DFMT_A32B32G32R32F,		//	RS_FORMAT_ARGB_F32				
	D3DFMT_R32F,				//	RS_FORMAT_R_F32					
	D3DFMT_D16,					//	RS_FORMAT_D16					
	D3DFMT_D24S8,				//	RS_FORMAT_D24_S8				
	D3DFMT_UNKNOWN,				//	RS_FORMAT_DEPTH_READABLE		
	D3DFMT_UNKNOWN,				//	RS_FORMAT_NULL					
};



D3DFORMAT GetD3DFormat(ERSFormat_t format) 
{
	return format_x_table[format];
}


ERSFormat_t	GetRSFormat(D3DFORMAT format) 
{
	for (uint i=0; i<RS_FORMAT_MAX; i++) {
		if (format_x_table[i]==format) {
			return (ERSFormat_t)(i);
		}
	}
	return RS_FORMAT_UNKNOWN;
}


const char *GetRSFormatName( ERSFormat_t format )
{
	STRINGIZE( format, RS_FORMAT_UNKNOWN		)
	STRINGIZE( format, RS_FORMAT_XRGB_U8		)
	STRINGIZE( format, RS_FORMAT_ARGB_U8		)
	STRINGIZE( format, RS_FORMAT_ARGB_U10		)
	STRINGIZE( format, RS_FORMAT_ARGB_F16		)
	STRINGIZE( format, RS_FORMAT_ARGB_F32		)
	STRINGIZE( format, RS_FORMAT_R_F32			)
	STRINGIZE( format, RS_FORMAT_D16			)
	STRINGIZE( format, RS_FORMAT_D24_S8			)
	STRINGIZE( format, RS_FORMAT_DEPTH_READABLE	)
	STRINGIZE( format, RS_FORMAT_NULL			)
	
	return "Unknown";
}
